<?php
namespace Admin\Controller;

use Utuo\BackgroundController;

class AdPositionTypeController extends BackgroundController{
	
	protected function _initialize(){
		$this->setControllerTitle("合作商广告位类别管理 ");
		$this->setActionTitle(array(
			'index' => '广告位类别列表',
			'add' => '广告位类别添加',
			'modify' => '广告位类别修改',
			'recycle' => '回收站'
		));
		$this->setActionNav(array(
			'index',
			'add',
			'recycle'
		));
	}
	
	// 广告位列表
	public function indexAction() {
		$this->getAdPositionList(0);
	}
	
	// 回收站
	public function recycleAction() {
		$this->getAdPositionList(1);
	}
	
	// 获得广告位列表
	public function getAdPositionList($is_deleted) {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$condition = array(
			'is_deleted' => $is_deleted
		);
		$adPositionTypeLists = M('PartnerAdPositionType')->where($condition)->limit($pagesize)->page($page)->order('id')->select();
		$adPositionTypeCount = M('PartnerAdPositionType')->where($condition)->count();
		$this->assign('adPositionTypeLists', $adPositionTypeLists);
		$this->showPage($adPositionTypeCount, $pagesize);
		$this->display();
	}
	
	
	// 广告位添加页面
	public function addAction() {
		$this->display();
	}
	
	// 提交广告位添加
	public function addPostAction() {
		$d = D('PartnerAdPositionType');
		if ($d->create()) {
			if ($d->add()) {
				$this->ajaxSuccess('添加广告位成功');
			} else {
				$this->ajaxError($d->getError());
			}
		} else {
			$this->ajaxError($d->getError());
		}
	}
	
	// 修改广告位
	public function modifyAction() {
		$id = I('id', 0, 'intval');
		$adPositionType = M('PartnerAdPositionType')->find($id);
		$this->assign('adPositionType', $adPositionType);
		$this->display();
	}
	
	// 提交广告位修改
	public function modifyPostAction() {
		$d = D('PartnerAdPositionType');
		if ($d->create()) {
			if (false !== $d->save()) {
				$this->ajaxSuccess('修改广告位成功');
			} else {
				$this->ajaxError($d->getError());
			}
		} else {
			$this->ajaxError($d->getError());
		}
	}
	
	// 移除广告位
	public function removePostAction() {
		$this->ajaxRemove('PartnerAdPositionType');
	}
	
	
	// 恢复广告位
	public function restorePostAction(){
		$this->ajaxRestore('PartnerAdPositionType');
	}
	
	
	// 彻底删除位
	public function deletePostAction(){
		$this->ajaxDelete('PartnerAdPositionType');
	}
}